package com.j2ee.struts.action.result;

import java.io.FileInputStream;
import java.io.InputStream;

import javax.servlet.ServletContext;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

/**
 * 文件下载——结果类型为stream的使用
 * @author LC
 *
 */
public class DownloadAction extends ActionSupport{
	
	private InputStream imageInputStream ;
	
	public InputStream getImageInputStream() {
		return imageInputStream;
	}

	public void setImageInputStream(InputStream imageInputStream) {
		this.imageInputStream = imageInputStream;
	}

	public String download() throws Exception{
		//得到文件的真实路径
		ServletContext servletContext = ServletActionContext.getServletContext() ;
		String filePath = servletContext.getRealPath("/WEB-INF/classes/1.jpg") ;
		//构建输入流
		imageInputStream = new FileInputStream(filePath) ;
		//用stream结果视图输入
		//返回逻辑视图
		return SUCCESS ;
	} 
	
	
	
}
